package com.heima.wemedia.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.heima.model.common.dtos.PageSensitive;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.pojos.WmChannel;
import com.heima.wemedia.mapper.WmChannelMapper;
import com.heima.wemedia.service.WmChannelService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
@Slf4j
public class WmChannelServiceImpl extends ServiceImpl<WmChannelMapper, WmChannel> implements WmChannelService {


    @Autowired
    private WmChannelService wmChannelService;

    @Override
    public ResponseResult findAll() {
        List<WmChannel> list = this.list();
        return ResponseResult.okResult(list);
    }

    @Override
    public ResponseResult Channelist(PageSensitive pageSensitive) {
        Page<WmChannel> page = new Page<>(pageSensitive.getPage(), pageSensitive.getSize());
        LambdaQueryWrapper<WmChannel> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(WmChannel::getName,pageSensitive.getName());
        Page<WmChannel> wmChannelPage = this.page(page, queryWrapper);
        List<WmChannel> records = wmChannelPage.getRecords();
        return ResponseResult.okResult(records);

    }
}
